#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：外观模式.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/3/1 23:55 
"""

"""
外观模式（Facade Pattern）
模式解释：
外观模式提供了一个统一的接口，用于访问子系统中的一组接口，从而简化了客户端与子系统之间的通信。
"""


class Subsystem1:
	def operation1(self):
		return "Subsystem1 operation1."

	def operation2(self):
		return "Subsystem1 operation2."


class Subsystem2:
	def operation1(self):
		return "Subsystem2 operation1."

	def operation2(self):
		return "Subsystem2 operation2."


class Facade:
	def __init__(self, subsystem1, subsystem2):
		self._subsystem1 = subsystem1
		self._subsystem2 = subsystem2

	def operation(self):
		results = []
		results.append("Facade operation:\n")
		results.append(self._subsystem1.operation1())
		results.append(self._subsystem1.operation2())
		results.append(self._subsystem2.operation1())
		results.append(self._subsystem2.operation2())
		return "\n".join(results)


subsystem1 = Subsystem1()
subsystem2 = Subsystem2()
facade = Facade(subsystem1, subsystem2)

print(facade.operation())
